﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Security.Permissions;
using System.Windows.Forms;

namespace Brewmaster
{
    [Serializable]
    public class TabMenuPage : ISerializable
    {
        private String text;

        private ContextMenuStrip menuStrip;

        public MenuRadioButton menuRadioButton;

        public Panel panel;

        public TabMenuPage()
        {
            menuRadioButton = new MenuRadioButton();
        }

        protected TabMenuPage(SerializationInfo info, StreamingContext context)
        {
            this.text = info.GetString("text");
            this.menuStrip = (ContextMenuStrip)info.GetValue("contextMenu", typeof(ContextMenuStrip));
            this.menuRadioButton = (MenuRadioButton)info.GetValue("button", typeof(MenuRadioButton));
            this.panel = (Panel)info.GetValue("panel", typeof(Panel));
            // we don't need the usual constructor since the menuRadioButton is already initialized
        }

        [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
        public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("text", this.text);
            info.AddValue("contextMenu", this.menuStrip);
            info.AddValue("button", this.menuRadioButton);
            info.AddValue("panel", this.panel);
        }

        public String Text
        {
            get
            {
                return text;
            }
            set
            {
                text = value;
                menuRadioButton.Label = text;
            }
        }
        
        public ContextMenuStrip MenuStrip
        {
            get
            {
                return menuStrip;
            }
            set
            {
                menuStrip = value;
                menuRadioButton.MenuStrip = menuStrip;
            }
        }
    }
}
